package cn.topevery.garden.wapi.utils;


import cn.afterturn.easypoi.excel.annotation.Excel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：peng.tian
 * @date ：Created in 2021/8/20 10:04
 * @description：数据处理工具
 */
public class DataUtils {
    public static Map<String,Integer> ToMap(List<Map<String,Object>> source,String key,String value){
        Map<String,Integer> target=new HashMap<>();
        source.forEach(f->{
            target.put(f.get(key).toString(),Integer.parseInt(f.get(value).toString()));
        });
        return target;
    }

    public static <T> Map<Integer,String> getAnnotationExcelReplace(Class<T> tClass,String attributeName) throws NoSuchFieldException {
        Map<Integer,String> target=new HashMap<>();
        String [] replace= tClass.getField(attributeName).getAnnotation(Excel.class).replace();
        if(replace.length>0){
            for (int i=0;i<replace.length;i++){
                String [] sp=replace[i].split("_");
                target.put(Integer.parseInt(sp[1]),sp[0]);
            }
        }
        return target;
    }
}
